package com.exp3;

import java.io.BufferedInputStream;
import java.util.Scanner;
import java.util.concurrent.BlockingDeque;

import javax.swing.JOptionPane;

/**
 * <p>
 * Title: Read
 * </p>
 * <p>
 * Description: 读取文件中的数据到list中
 * </p>
 * 
 * @author 詹金浩
 * @date 2018年11月6日
 */
public class ReadFromFile extends Thread {
	private BlockingDeque<String> list;
	public ReadFromFile(BlockingDeque<String> list){
		this.list = list;
	}
	public void run() {
		String line = null;
		try (Scanner cin = new Scanner(
				new BufferedInputStream(ReadFromFile.class.getResourceAsStream("/copy")))) {
			
			JOptionPane.showMessageDialog(null, "连接服务器成功");
			while(cin.hasNext()) {
				Thread.sleep(1l);
				line = cin.nextLine();
				list.put(line);
			}
			list.put("end");
			System.out.println("Read Thread has ended!");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
